package com.yc.jpyy.drivercarrel.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.yc.jpyy.base.service.BaseService;
import com.yc.jpyy.base.util.PageBean;
import com.yc.jpyy.drivercarrel.dao.DriverCarRelDao;
import com.yc.jpyy.drivercarrel.service.DriverCarRelService;


@Service
public class DriverCarRelServiceImpl extends BaseService implements DriverCarRelService {
    
	@Autowired
	private DriverCarRelDao DriverCarRelDao;

	

	@Override
	public int addDriverCarRelService(Map<String, Object> paramsMap) throws Exception {
		//通过存储过程取编号,将值赋给当前新增记录
		String number = DriverCarRelDao.getMaxNember(paramsMap);
		paramsMap.put("driverscard", number);
		int ret = DriverCarRelDao.addDriverCarRelDao(paramsMap);
		return ret;
	}

	
	
	
	

	@Override
	public Map<String, Object> findDriverCarRelByIDServer(Map<String, Object> paramsMap) throws DataAccessException {
	     return DriverCarRelDao.findDriverCarRelByIdDao(paramsMap);
	}

	

	@Override
	public PageBean findDriverCarRelService(Map<String, Object> paramsMap) throws DataAccessException {
		int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
		int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
		paramsMap.put("pagestart", (pagenum-1) * pagesize);
		List<Map<String, Object>> list = DriverCarRelDao.findDriverCarRelDao(paramsMap);
		PageBean pageBean = new PageBean();
		pageBean.setList(list);
		// 每页几条数据，默认20条
		pageBean.setPageSize(pagesize);
		// 得到数据库中的条数
		pageBean.setAllRow(this.findCountDriverCarRelService(paramsMap));
		// 当前第几页，默认第一页
		pageBean.setCurrentPage(pagenum);
		// 得到一共几页
		pageBean.setTotalPage(pageBean.getTotalPage());
		// 模仿百度分页，只显示10条数据
		pageBean.paginationTool(pagenum, pageBean.getTotalPage());
		return pageBean;
	}

	@Override
	public int findCountDriverCarRelService(Map<String, Object> paramsMap) throws DataAccessException {
		return DriverCarRelDao.findCountDriverCarRelDao(paramsMap);
	}

	@Override
	public int delforUpdateDriverCarRelService(Map<String, Object> InvestigInfo) throws DataAccessException {
		return DriverCarRelDao.delforUpdateDriverCarRelDao(InvestigInfo);
	}

	
	@Override
	public int delforUpdateDriverCarStatusService(Map<String, Object> paramsMap) throws DataAccessException {
		int ret = DriverCarRelDao.delforUpdateDriverCarStatusDao(paramsMap);
		return ret;
		
	}

	@Override
	public int findCountDriverFromDriverCarRelService(Map<String, Object> paramsMap) throws DataAccessException {
		return DriverCarRelDao.findCountDriverFromDriverCarRelDao(paramsMap);
	}






	@Override
	public int updateDriverCarStatusToDriverIDService(Map<String, Object> paramsMap) throws DataAccessException {
		// TODO Auto-generated method stub
		return DriverCarRelDao.updateDriverCarStatusToDriverIDDao(paramsMap);
	}






	@Override
	public List<Map<String, Object>> findDriverCarRelListService(Map<String, Object> paramsMap)
			throws DataAccessException {
		
		return DriverCarRelDao.findDriverCarRelListDao(paramsMap);
	}






	@Override
	public Map<String, Object> selectDriverInfo(Map<String, Object> paramsMap)
			throws DataAccessException {
		Map<String,Object> resultMap = new HashMap<>();
		//查询
		List<Map<String, Object>> list = DriverCarRelDao.selectDriverInfo(paramsMap);
		if(list != null && list.size() > 0){
			resultMap.put("returnCode", 1);
			resultMap.put("returnMsg", "查询成功");
			resultMap.put("ListData", list);	
		}else{
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "查询失败");
		}
		return resultMap;
	}

	@Override
	public Map<String, Object> updateDriverCarReStatus(Map<String, Object> paramsMap)
			throws DataAccessException {
		Map<String,Object> resultMap = new HashMap<>();
		String vehicleid = Optional.ofNullable(paramsMap.get("vehicleid")).orElse("").toString();
		paramsMap.put("vehicleid", vehicleid.equals("")?"":vehicleid.split(","));
		int i = DriverCarRelDao.updateDriverCarReStatus(paramsMap);
		if( i > 0){
			resultMap.put("returnCode", 1);
			resultMap.put("returnMsg", "更改成功");	
		}else{
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "更改失败");
		}
		return resultMap;
	}
	
}
